<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .wrap {
            width: 400px;
            height: 400px;
            border: 1px solid #e15761;
            padding-top: 80px;
            overflow: auto;
        }
        .content {
            margin: 20px;
            width: 600px;
            height: 600px;
            line-height: 60px;
            background-color: #f5dc3a;
        }
    </style>
</head>
<body>
    <button onclick="getScroll()">获取滚动条</button>
    <div class="wrap">
        <div class="content">
            这是一个div
            <span class="span">快要下课了</span>
        </div>
    </div>
    <script>
        var div1 = document.querySelector('.wrap')
        var div2 = document.querySelector('.content')
        var span1 = document.querySelector('.span')
        // 只读属性，只能看不能改
        // offsetLeft 当前元素和父元素的左侧距离
        console.log(div2.offsetLeft);
        // offsetTop 当前元素和父元素的上面的距离
        console.log(div2.offsetTop);
        // 当前元素的宽高
        console.log(div2.offsetWidth);
        console.log(div2.offsetHeight);
        //  获取父容器
        console.log(div2.offsetParent);
        console.log(span1.offsetParent);
        // 获取滚动条的值
        console.log(div2.scrollTop);
        console.log(div2.clientWidth);
        console.log(div2.clientHeight);
        function getScroll () {
            // 获取元素横向以及纵向的滚动距离
            console.log('X:', div1.scrollLeft, 'Y:', div1.scrollTop);
        }
    </script>
</body>
</html>